<template>
  <li :class="status">
    <span class="task-title">{{ task.title }}</span>
    <div class="task-actions">
      <button class="btn-execute" @click="handleClick('execute')">执行</button>
      <button class="btn-pause" @click="handleClick('pause')">暂停</button>
      <button class="btn-edit" @click="handleClick('edit')">编辑</button>
      <button class="btn-delete" @click="handleClick('delete')">删除</button>
    </div>
  </li>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue';

// 定义 props
const props = defineProps({
  task: {
    type: Object,
    required: true,
  },
  status: {
    type: String,
    default: '',
  },
});

// 定义 emits
const emit = defineEmits(['action']);

// 处理按钮点击
const handleClick = (actionType) => {
  emit('action', actionType, props.task); // 传递事件类型和任务内容
};
</script>

<style scoped>
li {
  padding: 20px;
  border-radius: 12px;
  background-color: white;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}

li:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

li.未开始 {
  border-left: 6px solid #ffa500;
}

li.进行中 {
  border-left: 6px solid #1e90ff;
}

li.已完成 {
  border-left: 6px solid #32cd32;
}

li.已删除 {
  border-left: 6px solid #ff4500;
}

li.新计划 {
  border-left: 6px solid #9370db;
}

.task-title {
  font-size: 18px;
  font-weight: 500;
}

.task-actions {
  display: flex;
  gap: 10px;
}

.task-actions button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.3s ease, transform 0.3s ease, box-shadow 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.task-actions button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.btn-execute {
  background-color: #32cd32; /* 绿色 */
  color: white;
}

.btn-execute:hover {
  background-color: #2d8c4a;
}

.btn-pause {
  background-color: #ffa500; /* 橙色 */
  color: white;
}

.btn-pause:hover {
  background-color: #cc8400;
}

.btn-edit {
  background-color: #1e90ff; /* 蓝色 */
  color: white;
}

.btn-edit:hover {
  background-color: #0077cc;
}

.btn-delete {
  background-color: #ff4500; /* 红色 */
  color: white;
}

.btn-delete:hover {
  background-color: #cc0000;
}
</style>